package hpasControllers;

import hpasDataEntities.Hardware;
import hpasUserInterfaces.itemQueryPage.HardwareQuery;
import hpasUserInterfaces.userLoginPage.UserLogin;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class UserLoginController implements ActionListener
{
    private JTextField tfUsername;
    private JPasswordField pfPass;
    private JButton btLogin;
    private JButton btGuestLogin;
    private JFrame parent;

    public UserLoginController()
    {

    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource()==btLogin)
        {
            if (tfUsername.getText().equals("user") && new String(pfPass.getPassword()).equals("hakurei"))
            {
                HardwareQuery queryUI = new HardwareQuery("IT硬件报价系统 - "+"user"+" (注册消费者) ");
                queryUI.setVisible(true);
                parent.dispose();
            }
            else
            {
                JOptionPane.showMessageDialog(null,"用户名或密码错误，请重试",
                        "错误",JOptionPane.ERROR_MESSAGE);
            }
        }
        else if (e.getSource()==btGuestLogin)
        {
            HardwareQuery queryUI = new HardwareQuery();
            queryUI.setVisible(true);
            parent.dispose();
        }
    }

    public void setUsername(JTextField tfUsername)
    {
        this.tfUsername = tfUsername;
    }
    public void setPass(JPasswordField pfPass)
    {
        this.pfPass = pfPass;
    }

    public void setBtLogin(JButton btLogin)
    {
        this.btLogin = btLogin;
    }

    public void setBtGuestLogin(JButton btGuestLogin)
    {
        this.btGuestLogin = btGuestLogin;
    }

    public void setParent(JFrame parent)
    {
        this.parent = parent;
    }
}
